home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 026-050 / scopedisk31 / xmake / xmake.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-19  |  5.0 KB  |  201 lines

  1.  
  2. /*  This routine is a utility to read a MAKEFILE used by the MAKE
  3.     utility and recover, display, and print an alphabetic listing
  4.     of all FUNCTIONS found in the source files.
  5. */
  6.  
  7.  
  8. #include <exec/types.h>
  9. #include <libraries/dos.h>
  10. #include <libraries/dosextens.h>
  11. #include <stdio.h>
  12. #include <ctype.h>
  13. #include <exec/memory.h>
  14.  
  15. char str[120], c[190], line[190], filename[190], lin[190], file[180];
  16. int toggle, ll, a, p, mkin, vv;
  17. char *x,*y,*z, *xx;
  18. int per1,os,coln,per2,cs,LineCount,lparen,rparen,ss,mk;
  19.  
  20.  
  21. /*************************/
  22. void main()
  23. {
  24.    FILE *fb, *ib, *ob;
  25.  
  26.    if((fb = fopen("makefile","r")) == NULL) {
  27.       printf("Error.. can't open MAKEFILE");
  28.       exit(100);
  29.    }
  30.    if((ob = fopen(".FUNCT","w")) == NULL) {
  31.       printf("Error.. can't open .FUNCT file");
  32.       fclose(fb);
  33.       exit(101);
  34.    }
  35. vv=0;
  36.  
  37. NEXTLINE:
  38.    xx = fgets(c,190,fb);
  39.    vv++;
  40.    if (xx==NULL) { goto Main_Exit;}   /* end of makefile */
  41.    ll=strlen(c);
  42.    if (ll<5) {
  43.       printf("\n%d Line too short",vv);
  44.       goto NEXTLINE;
  45.    }
  46.                                /* if (c[0]==0x20) {goto NEXTLINE;} */
  47.    per1 = os = coln = per2 = cs = 0;
  48.    for (mkin=0;mkin < ll; mkin++) {
  49.       if(c[mkin]==0x2e) {       /* period */
  50.           if((per1==0)&&(c[mkin+1]==0x6f)) {   /* o */
  51.                  per1=mkin;
  52.                  os=mkin+1;
  53.           }
  54.           if((per1>0)&&(c[mkin+1]==0x63)&&(coln>0)) { /* c */
  55.                  per2=mkin;
  56.                  cs=mkin+1;
  57.           }
  58.        }
  59.        if(c[mkin]==0x3a) {               /* colon */
  60.           if((per1>0)&&(per2==0)) {
  61.                  coln=mkin;
  62.            }
  63.        }
  64.     }       /* end of FOR */
  65.   if((per1==0)||(per2==0)||(coln==0)) {goto NEXTLINE;}
  66.   if((per1>coln)||(per2<coln)) { goto NEXTLINE;}  /*UN- successful line */
  67.      mkin=coln+1;
  68.      while(c[mkin]==0x20) {mkin++;}
  69.      per2+=2;
  70.      c[per2]=0x00;
  71.      strcpy(&file,&c[mkin]);
  72.      printf("\nProcessing >%s<\n\n",file);
  73.  
  74.      if((ib=fopen(file,"r"))==NULL) {
  75.          printf("\nError... cannot open >%s<\n",file);
  76.          goto NEXTLINE;
  77.      }
  78. /* NOW TO READ THE SOURCE FILE */
  79.  
  80.    LineCount = 0;
  81.    toggle = 0;
  82. NEXTIN:
  83.  
  84.    lparen = rparen = 0;
  85.    ss = mk = 999;              /* 1st space before fname */
  86.    xx=fgets(c,190,ib);
  87.    if(xx==NULL){
  88.       fclose(ib);
  89.       goto NEXTLINE;
  90.    }
  91.  
  92.     LineCount++;
  93.     mkin=strlen(c);
  94.     if (mkin<4) {goto NEXTIN;}
  95.     for( ;mkin>0;mkin--) {
  96.         if((c[mkin]==0x2f)&&(c[mkin+1]==0x2a)){
  97.            toggle=1;
  98.            goto MOREFOR;
  99.         }
  100.         if((c[mkin]==0x2a)&&(c[mkin+1]==0x2f)){
  101.            toggle=0;
  102.            goto MOREFOR;
  103.         }
  104.         if (toggle == 1) {goto MOREFOR;}
  105.         
  106.  
  107.         if((c[mkin]==0x0a)||(c[mkin]==0x0d)) {c[mkin]=0x00;}
  108.         if((c[mkin]==0x3b)||(c[mkin]==0x7d)||(c[mkin]==0x26)||
  109.            (c[mkin]==0x7c)||(c[mkin]==0x7b)) { goto NEXTIN;}
  110.         if(c[mkin]==0x28) {lparen = mkin;}      /* left paren  */
  111.         if(c[mkin]==0x29) {rparen = mkin;}      /* right paren */
  112.         if ((c[mkin]==0x20)&&(lparen>0)&&(rparen>0)&&(mk!=999)&&(ss==999)){
  113.                ss=mkin;
  114.                   }
  115.         if ((isalpha(c[mkin]))!=0) {
  116.            if ((lparen>0)&&(rparen>0)) {
  117.               mk=mkin;
  118.            }
  119.         }
  120. MOREFOR:
  121.    }       /* end of FOR */
  122.  
  123.    if((lparen==0)||(rparen<=lparen)) { goto NEXTIN;}   /* FAIL */
  124.       if(ss==999) {
  125.          ss=0;
  126.        } else {
  127.          ss++;
  128.        }
  129.        strcpy(line,&c[ss]);
  130.        strupr(line);
  131.  
  132.  
  133. /* START LOOKING FOR SPECIALS */
  134.  
  135.        if((stcpm(line,"IF(+",z))!=0) {goto NEXTIN;}
  136.        if((stcpm(line,"SWITCH(+",z))!=0) {goto NEXTIN;}
  137.        if((stcpm(line,"WHILE(+",z))!=0) {goto NEXTIN;}
  138.        if((stcpm(line,"DO(+",z))!=0) {goto NEXTIN;}
  139.        if((stcpm(line,"IF (+",z))!=0) {goto NEXTIN;}
  140.        if((stcpm(line,">+",z))!=0) {goto NEXTIN;}
  141.        if((stcpm(line,"<+",z))!=0) {goto NEXTIN;}
  142.        if((stcpm(line,"LONG)+",z))!=0) {goto NEXTIN;}
  143.        if((stcpm(line,"SIZEOF(+",z))!=0) {goto NEXTIN;}
  144.        if((stcpm(line,"=+",z))!=0) {goto NEXTIN;}
  145.    
  146.  
  147.        for(a=0;a<strlen(line);a++) {
  148.            if(line[a]==0x2a) {goto NEXTIN;}
  149.        }
  150.        if(line[0]==0x20) {goto NEXTIN;}
  151.        if(line[0]==0x28) {goto NEXTIN;}
  152.  
  153.  
  154.        sprintf(str,"%-25.25s %-25.25s %4.4d %20.20s\n",
  155.              line,&c[ss],LineCount,file);
  156.        printf("%s",str);
  157.        fputs(str,ob);
  158.        goto NEXTIN;
  159.  
  160. Main_Exit:
  161.       if(fb) { fclose(fb);}
  162.       if(ob) { fclose(ob);}
  163.       printf("\n\nEND OF write!!!\n\n");
  164.       printf("\n%d Makefile lines processed!\n",vv);
  165.  
  166.       Execute("sort .FUNCT to .SUNCT",0,0);
  167.  
  168.  
  169.    if((fb = fopen(".SUNCT","r")) == NULL) {
  170.       printf("Error.. can't open MAKEFILE");
  171.       exit(100);
  172.    }
  173.    if((ob = fopen("SORTED.FUNCTIONS","w")) == NULL) {
  174.       printf("Error.. can't open OUTPUT file");
  175.       fclose(fb);
  176.       exit(101);
  177.    }
  178.  
  179. SPINWRITE:   
  180.    xx = fgets(c,190,fb);
  181.    if (xx==NULL) { goto Final_Exit;}   /* end of makefile */
  182.    strcpy(line,&c[26]);
  183.    printf("%s",line);
  184.    fputs(line,ob);
  185.    goto SPINWRITE;
  186.  
  187. Final_Exit:
  188.    fclose(fb);
  189.    fclose(ob);
  190.  
  191. }
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.          
  200.  
  201.